import time
from selenium.webdriver.common.by import By
from common.Utils import BlogDriver

class BlogList:
    driver = ""
    url = ""
    def __init__(self):
        self.driver = BlogDriver.driver
        self.url = "http://8.137.19.140:9090/blog_list.html"
        self.driver.get(self.url)

    def BlogLoginListTest(self):#登路状态下
        #检查一下博客的标题是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > div.title")
        #检查一下发布博客的时间是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > div.date")
        #检查一下博客的内容是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > div.desc")
        #检查一下博客列表页的查看全文按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > a")
        #检查一下用户基本信息的昵称是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > h3")
        #检查一下用户基本信息的文章是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > div:nth-child(4) > span:nth-child(1)")
        #检查一下用户基本信息的分类是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > div:nth-child(4) > span:nth-child(2)")
        #检查一下博客数量是否为0，不为就就通过
        Blognum = self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > div:nth-child(5) > span:nth-child(1)").text
        print(Blognum)
        assert Blognum != 0
        BlogDriver.GetScreeShot()
        # self.driver.quit()

    def NotBlogLoginListTest(self):  #未登录状态下
        # # 找到用户命名输入框和密码输入框把里面的内容清空
        # self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.get("http://8.137.19.140:9090/blog_list.html")
        time.sleep(2)
        BlogDriver.GetScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div:nth-child(1) > div.title")


    def QuitBlogLoginListText(self):  # 登录博客状态下测试退出
        #点击退出按钮
        self.driver.find_element(By.CSS_SELECTOR, "body > div.nav > a:nth-child(6)").click()
        BlogDriver.GetScreeShot()
        #判断一下退出后的页面url和页面的标题
        Quittitle = self.driver.title
        QuitUrl = self.driver.current_url
        print(Quittitle)
        print(QuitUrl)
        assert Quittitle == "博客登陆页"
        assert QuitUrl == "http://8.137.19.140:9090/blog_login.html"
        #判断一下账号输入框和密码输入框的内容是否为空
        Quitusername = self.driver.find_element(By.CSS_SELECTOR,"#username").text
        Quitpassword = self.driver.find_element(By.CSS_SELECTOR,"#password").text
        print("Quitusername"+Quitusername)
        print("Quitpassword"+Quitpassword)
        assert Quitusername == ""
        assert Quitpassword == ""

